namespace uTILLIty.Rave.Contract.StorageAdapter
{
  /// <summary>
  /// Information about a member in the target storage
  /// </summary>
  public class StorageMember
  {
    /// <summary>
    /// Creates a new instance of a <see cref="StorageMember"/>
    /// </summary>
    /// <remarks>
    /// An instance of this class is created as a result of member-resolution or creation
    /// in the backend credential store
    /// </remarks>
		/// <param name="id">A unique identifier of the member in the target storage</param>
		/// <param name="targetMember">The actual member-object in the target storage</param>
		public StorageMember(string id, object targetMember)
    {
      ID = id;
      TargetMember = targetMember;
    }

    /// <summary>
    /// A unique identifier of the member in the target storage
    /// </summary>
    public string ID { get; set; }

    /// <summary>
    /// The actual member-object in the target storage
    /// </summary>
    public object TargetMember { get; set; }

  	/// <summary>
  	/// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
  	/// </summary>
  	/// <returns>
  	/// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
  	/// </returns>
  	/// <filterpriority>2</filterpriority>
  	public override string ToString()
    {
    	var targetMember = string.Format("{0}", TargetMember ?? "[null]");
			return targetMember.Contains(ID) ? targetMember : string.Format("{0} {{{1}}}", ID, targetMember);
    }

  	/// <summary>
  	/// Wether the current instance referencially or semantically equals the <paramref name="other">supplied</paramref>
  	/// instance
  	/// </summary>
  	/// <remarks>
  	/// The <see cref="ID"/> is the sole comparison property for this operation
  	/// </remarks>
  	/// <param name="other">The instance to compare this instance to</param>
  	/// <returns>True, if the instances referencially or semantically equal, else false</returns>
  	public bool Equals(StorageMember other)
  	{
  		if (ReferenceEquals(null, other)) return false;
  		if (ReferenceEquals(this, other)) return true;
  		return Equals(other.ID, ID);
  	}

  	/// <summary>
  	/// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
  	/// </summary>
  	/// <returns>
  	/// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false.
  	/// </returns>
  	/// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>. </param><filterpriority>2</filterpriority>
  	public override bool Equals(object obj)
  	{
  		if (ReferenceEquals(null, obj)) return false;
  		if (ReferenceEquals(this, obj)) return true;
  		if (obj.GetType() != typeof (StorageMember)) return false;
  		return Equals((StorageMember) obj);
  	}

  	/// <summary>
  	/// Serves as a hash function for a particular type. 
  	/// </summary>
  	/// <returns>
  	/// A hash code for the current <see cref="T:System.Object"/>.
  	/// </returns>
  	/// <filterpriority>2</filterpriority>
  	public override int GetHashCode()
  	{
  		return (ID != null ? ID.GetHashCode() : 0);
  	}
  }
}